"""
进程池
"""
import os
from multiprocessing import Pool
from random import random
import time


# 阻塞式进程


def fun_task(task_name):
    print("{} -> 开始做任务了".format(task_name))
    start = time.time()
    time.sleep(random() * 2)
    end = time.time()
    print("{} -> 完成任务 , 用时 -> {} , 进程ID -> {}".format(task_name, end - start, os.getpid()))


if __name__ == '__main__':

    pool = Pool(5)

    tasks = ['吃饭', '睡觉', '打豆豆', '听歌', '看剧', '打球', '跑步', '逛街']
    for i in tasks:
        process = pool.apply(fun_task, args=(i,))

    print("任务全部执行结束")
